using System;
using System.Collections.Generic;
using System.IO;
using NMock2;

namespace NMockExtensions
{
    [Obsolete(
        @"This mechanism is unrelyable as the matcher maybe called several times for a single call to the method.
    Use: .Will(Execute.Delegate(delegate(Invocation invocation) { localVariable = invocation.Parameters[?] })"
        )]
    public class RememberingMatcher<aType> : Matcher
    {
        private readonly List<aType> objs = new List<aType>();

        public override bool Matches(object o)
        {
            objs.Add((aType) o);
            return true;
        }

        public override void DescribeTo(TextWriter writer)
        {
            writer.WriteLine("Remembering object ");
        }

        public aType Remembered(int index)
        {
            return objs[index];
        }
    }
}